package com.dashboard.giangday;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import com.lb.jwitter.connectDatabase.ConnectTTGD;
import com.opensymphony.xwork2.Action;

public class ListBoMon {
	private ArrayList<HashMap<String, String>> listBoMon;
	
	
	public ArrayList<HashMap<String, String>> getListBoMon() {
		return listBoMon;
	}


	public void setListBoMon(ArrayList<HashMap<String, String>> listBoMon) {
		this.listBoMon = listBoMon;
	}
	private String maKhoa;
	

	public String getMaKhoa() {
		return maKhoa;
	}


	public void setMaKhoa(String maKhoa) {
		this.maKhoa = maKhoa;
	}


	public String execute() throws Exception
	{
		if(maKhoa==null||maKhoa.length()<1){
			return Action.ERROR;
		}
		ConnectTTGD connectionOracle= new ConnectTTGD();
		if(connectionOracle.getConnection()!=null){
			listBoMon=new ArrayList<HashMap<String, String>>();
			String query="select distinct maBoMon, tenBoMon from bomon_view where maBoMon is not null and maKhoa='"+maKhoa+"'";
			HashMap<String,String> map;	
			ResultSet data=connectionOracle.getData(query);
			if(data!=null){
				while(data.next()){
					map = new HashMap<String,String>();
					String maBoMon=data.getString("maBoMon");
					String tenBoMon=data.getString("tenBoMon");
					map.put("maBoMon", maBoMon);
					map.put("tenBoMon", tenBoMon);
					listBoMon.add(map);
				}
			}
			
		}
		connectionOracle.closeConnection();
		return Action.SUCCESS;

	}
}
